package main

import (
	"fmt"
	"sync"
)

// 线程安全，多个线程访问同一资源，产生资源竞争，最终结果不正确

var money int = 0
var lock sync.RWMutex

func add(pint *int) {

	lock.Lock()
	for i := 0; i < 100000; i++ {
		*pint++
	}
	lock.Unlock()
}

func main() {
	for i := 0; i < 1000; i++ {
		add(&money)
	}

	//time.Sleep(time.Second*20)
	fmt.Println(money)
}
